﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Common.Logging;

namespace SupportLibrary.WebMethod
{
    public class WebResource
    {
        private static string _path = System.IO.Directory.GetCurrentDirectory() + "\\" + "TagList.xml";
        public WebResource()
        {
 
        }

        public static Dictionary<String, String> Tags()
        {
            Dictionary<string, string> tags = new Dictionary<string, string>();
           
            if (FileIO.IsExist(_path))
            {
                XElement root = XElement.Load(_path);
                //var listTags = root.Elements("tag");

                var listTags = root.Elements("tag");
                               //where tag.Element("name").Value.Equals(tagName)
                               //select tag.Element("attribute").Value;
                foreach (XElement tag in listTags)
                {
                    tags.Add(tag.Element("name").Value, tag.Element("attribute").Value);
                    
                }
                
                //
            }
            return tags;
        }
        //each attribute was separated by a comma
        public static List<String> Attributes(string attribute)
        {
            List<String> attributes = new List<string>();
            var attarray = attribute.Split(',');

            foreach (string attr in attarray)
            {
                attributes.Add(attr);
            }

            return attributes;
        }

        //each page was separated by a comma
        public static List<String> Pages(String listPages)
        {
            List<String> pages = new List<string>();
            var attarray = listPages.Split(',');

            foreach (string attr in attarray)
            {
                pages.Add(attr);
            }

            return pages;
        }
    }
}
